/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BL;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author sundas
 */
@Entity
@Table(name = "person", catalog = "newPurchase", schema = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"NIC"})})
@NamedQueries({@NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"), @NamedQuery(name = "Person.findByName", query = "SELECT p FROM Person p WHERE p.name = :name"), @NamedQuery(name = "Person.findByAddress", query = "SELECT p FROM Person p WHERE p.address = :address"), @NamedQuery(name = "Person.findByMobileNo", query = "SELECT p FROM Person p WHERE p.mobileNo = :mobileNo"), @NamedQuery(name = "Person.findByNic", query = "SELECT p FROM Person p WHERE p.nic = :nic"), @NamedQuery(name = "Person.findByEmail", query = "SELECT p FROM Person p WHERE p.email = :email"), @NamedQuery(name = "Person.findByContactNo", query = "SELECT p FROM Person p WHERE p.contactNo = :contactNo"), @NamedQuery(name = "Person.findByType", query = "SELECT p FROM Person p WHERE p.type = :type")})
public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @Column(name = "name", nullable = false, length = 50)
    private String name;
    @Basic(optional = false)
    @Column(name = "address", nullable = false, length = 18)
    private String address;
    @Basic(optional = false)
    @Column(name = "mobileNo", nullable = false, length = 12)
    private String mobileNo;
    @Id
    @Basic(optional = false)
    @Column(name = "NIC", nullable = false, length = 15)
    private String nic;
    @Column(name = "email", length = 50)
    private String email;
    @Column(name = "contactNo", length = 30)
    private String contactNo;
    @Column(name = "type")
    private Integer type;
    @OneToMany(mappedBy = "nic")
    private Collection<Systemuser> systemuserCollection;
    @OneToMany(mappedBy = "nic")
    private Collection<Customer> customerCollection;
    @OneToMany(mappedBy = "nic")
    private Collection<Supplier> supplierCollection;

    public Person() {
    }

    public Person(String nic) {
        this.nic = nic;
    }

    public Person(String nic, String name, String address, String mobileNo) {
        this.nic = nic;
        this.name = name;
        this.address = address;
        this.mobileNo = mobileNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getMobileNo() {
        return mobileNo;
    }

    public void setMobileNo(String mobileNo) {
        this.mobileNo = mobileNo;
    }

    public String getNic() {
        return nic;
    }

    public void setNic(String nic) {
        this.nic = nic;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getContactNo() {
        return contactNo;
    }

    public void setContactNo(String contactNo) {
        this.contactNo = contactNo;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Collection<Systemuser> getSystemuserCollection() {
        return systemuserCollection;
    }

    public void setSystemuserCollection(Collection<Systemuser> systemuserCollection) {
        this.systemuserCollection = systemuserCollection;
    }

    public Collection<Customer> getCustomerCollection() {
        return customerCollection;
    }

    public void setCustomerCollection(Collection<Customer> customerCollection) {
        this.customerCollection = customerCollection;
    }

    public Collection<Supplier> getSupplierCollection() {
        return supplierCollection;
    }

    public void setSupplierCollection(Collection<Supplier> supplierCollection) {
        this.supplierCollection = supplierCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (nic != null ? nic.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.nic == null && other.nic != null) || (this.nic != null && !this.nic.equals(other.nic))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.Person[nic=" + nic + "]";
    }

}
